@extends('admin.layouts.content')
@section('script')
<script>
    new Wanyue().layuiAdmin.list({
        search: [{
            type: 'text', title: '角色名称', name: 'like[name]'
        }]
        , actions: [{
            title: '添加角色'
            , btn: 'layui-btn-normal'
            , handler: function(self, data) {
                self.open({
                    title: '添加角色'
                    , offset: '120px'
                    , area: ['60%', '60%']
                    , url: '{{ url("admin/roles/create") }}'
                });
            }
        }]
    }, {
        url: '{{ url()->current() }}'
        , fields: [
            {type: 'numbers', fixed: 'left'}
            , {field: 'name', title: '角色名称', width: 120}
            , {field: 'code', title: '角色编码', width: 200}
            , {field: 'remark', title: '角色描述', width: 340}
            , {field: 'is_disabled', title: '状态', width: 100, templet: function(d) {
                return d.is_disabled == 1 ? '<span style="color:red">已禁用</span>' : '<span style="color:green">已启用</span>'
            }}
            , {field: 'created_at', title: '创建时间', width: 200}
        ]
        , csrf: {name: '_token', value: '{!! csrf_token() !!}'}
        , toolbars: {
            width: 240
            , list: [{
                title: '编辑'
                , btn: 'layui-btn-normal'
                , icon: 'layui-icon-edit'
                , handler: function(open, data) {
                    open({
                        type: 'open'
                        , offset: '120px'
                        , area: ['60%', '60%']
                        , title: '编辑'
                        , url: '{{ url("admin/roles/update", ["id" => "__ID__"]) }}'.replace('__ID__', data.id)
                    });
                }
            }, {
                title: '分配权限'
                , btn: 'layui-btn-warm'
                , icon: 'layui-icon-set'
                , handler: function(open, data) {
                    open({
                        type: 'open'
                        , title: '分配权限'
                        , url: '{{ url("admin/roles/relate", ["id" => "__ID__"]) }}'.replace('__ID__', data.id)
                    });
                }
            }, {
                type: 'mutiple'
                , title: ['启用', '禁用']
                , btn: ['layui-btn-danger', 'layui-btn-danger']
                , icon: ['layui-icon-ok', 'layui-icon-close']
                , when: ['is_disabled == 1', 'is_disabled == 0']
                , handler: function(open, data) {
                    open({
                        type: 'confirm'
                        , title: ['启用', '禁用']
                        , url: ['{{url("admin/roles/enable")}}', '{{url("admin/roles/disable")}}']
                        , updated: {fields: [{'is_disabled': '0'}, {'is_disabled': '1'}], trigger: function(e) {}}
                    });
                }
            }]
        }
    });
</script>
@endsection
